package cn.edu.flow.test;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;

/**
 * 测试流程部署
 */
@Slf4j
@SpringBootTest
public class Part1_Deployment {

    @Autowired
    private RepositoryService repositoryService;

    /**
     * 通过bpmn部署流程
     */
    @Test
    public void initDeploymentBPMN(){
        String fileName = "BPMN/Part7_Parallel.bpmn";
        //String pngName = "BPMN/Part1_Deployment.png";
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource(fileName)
               // .addClasspathResource(pngName)
                .name("并行网关")
                .deploy();

        log.info(deployment.getName());
    }

    /**
     * 查询流程部署
     */
    @Test
    public void getDeployments() {
        List<Deployment> list = repositoryService.createDeploymentQuery().list();
        for(Deployment dep : list){
            log.info("Id："+dep.getId());
            log.info("Name："+dep.getName());
            log.info("DeploymentTime："+dep.getDeploymentTime());
            log.info("Key："+dep.getKey());
        }

    }


    /**
     * 通过ZIP部署流程
     */
    @Test
    public void initDeploymentZIP() {
        InputStream fileInputStream = this.getClass()
                .getClassLoader()
                .getResourceAsStream("BPMN/Part1_DeploymentV2.zip");
        ZipInputStream zip = new ZipInputStream(fileInputStream);
        Deployment deployment=repositoryService.createDeployment()
                .addZipInputStream(zip)
                .name("流程部署测试zip")
                .deploy();

        log.info(deployment.getName());
    }
}
